package thread;

public class Demo9 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //e.printStackTrace();
                    break;
                }
            }
        });
        t.start();

        Thread.sleep(3000);
        System.out.println("终止线程Thread");
        t.interrupt();//终止线程的时候还会唤醒像sleep这样的阻塞方法
    }
}
